/*
 * Last review by   : Yaser
 * Last review date : JUL-25-09 
 */
using System.Data;
using ERP.Framework.Components.Utilities.TracingHelper;

namespace ERP.Framework.Components.DatabaseHelper
{
    /// <summary>
    /// Conver parameter's properties to known .NET type
    /// </summary>
    public abstract class ParameterConvertor
    {
        private const string TRACING_CATEGORY = "ERP.Framework.Components.DatabaseHelper.ParameterConvertor";

        #region Methods

        /// <summary>
        /// Convert to .NET ParameterDirection
        /// </summary>
        /// <param name="direction">Parameter direction</param>
        /// <returns>The euivelent .NET ParameterDirection</returns>
        public static System.Data.ParameterDirection GetDirection(ParameterDirection direction)
        {
            TraceUtil.Write(TRACING_CATEGORY, string.Format("GetDirection : Custom direction : {0}", direction.ToString()));
            switch (direction)
            {
                case ParameterDirection.InParameter:
                    return System.Data.ParameterDirection.Input;
                case ParameterDirection.OutParameter:
                    return System.Data.ParameterDirection.Output;
                default:
                    return System.Data.ParameterDirection.InputOutput;
            }
        }

        /// <summary>
        /// Convert to SQL parameter type
        /// </summary>
        /// <param name="type">Parameter type</param>
        /// <returns>The equivelent SQL type</returns>
        public static SqlDbType GetSQLType(ParameterType type)
        {
            TraceUtil.Write(TRACING_CATEGORY, string.Format("GetSQLType : Custom type : {0}", type.ToString()));
            switch (type)
            {
                case ParameterType.String:
                    return SqlDbType.VarChar;
                case ParameterType.Int:
                    return SqlDbType.Int;
                case ParameterType.Double:
                    return SqlDbType.Float;
                case ParameterType.Char:
                    return SqlDbType.Char;
                case ParameterType.DateTime:
                    return SqlDbType.DateTime;
                case ParameterType.LongInt:
                    return SqlDbType.BigInt;
                case ParameterType.Boolean:
                    return SqlDbType.Bit;
                default:
                    return SqlDbType.Text;
            }
        }

        #endregion
    }
}
